package com.sortingalgorithm;

import java.time.LocalDateTime;
import java.util.Arrays;

public class InsertSort2 {
    public static void main(String[] args) {
        int[] data = {1,4,-4,9,23,-58,0};
        insertSort2(data);
        System.out.println(Arrays.toString(data));
    }

    // 插入排序
    private static void insertSort2(int[] data){
        if(data == null || data.length < 2){
            return;
        }
        int len = data.length;
        for (int i = 1; i < len; i++) {
            int j = i;
            int temp = data[i];
            while (j > 0 && data[j - 1] > temp){
                data[j] = data[j - 1];
                j--;
            }
            data[j] = temp;
        }

        LocalDateTime dateTime = LocalDateTime.now();
        System.out.println(dateTime);

    }
}
